package student.aistar.snake;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

public class SnakeGames {
    //定义行和列
    public static final int ROWS = 20;
    public static final int COLS = 20;

    //定义一个集合, 用来存食物的坐标
    Set<Point> food = new HashSet<>();

    public SnakeGames() {
//        this.food = food;
        init(3);


    }

    private void init(int n) {//食物的数量
        while (true){
            int x = (int) (Math.random()*18 + 1);
            int y = (int) (Math.random()*18 + 1);

            Point point = new Point(x, y);

            food.add(point);

            if(food.size() == n){
                break;
            }

        }
    }

    //打印游戏页面
    public void start(){
        for(int i = 0; i < ROWS; i++){
            for(int j = 0; j < COLS; j++){
                if(i == 0 || j == 0 || i == 19 || j == 19)
                    System.out.printf("%2s", "*");
                else if(food.contains(new Point(i, j)))
                    System.out.printf("%2s", "0");
                else {
                    System.out.printf("%2s","");
                }
            }
            System.out.println();
        }
    }

    //搞蛇, 内部类
    public class Snake{
        private LinkedList<Point> snake = new LinkedList<>();

        public final int UP = 1;
        public final int DOWN = -1;
        public final int LEFT =2;
        private final int RIGHT = -2;

        public Snake() {
//            this.snake = snake;
            //x纵坐标,y横坐标
            snake.add(new Point(5,8));//头结点
            snake.add(new Point(5,9));
            snake.add(new Point(5,10));
            snake.add(new Point(5,11));
        }


    }
}
